package com.abel.bigwater.dataserver.model.qdies

import com.abel.bigwater.data.BcdString
import io.netty.buffer.Unpooled
import org.junit.Assert.assertEquals
import org.junit.Test
import org.slf4j.LoggerFactory

class MainLoginDataTest {

    @Test
    fun fill() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.Login
            data = MainLoginData()

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals(DEMO_LOGIN, str)
    }

    @Test
    fun fillHeart() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.Heart
            data = MainHeartData()

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals(DEMO_HEART, str)
    }

    @Test
    fun fillState() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.AskState
            data = MainAskStateData()

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals(DEMO_ASK_STATE, str)

    }

    companion object {
        private val lgr = LoggerFactory.getLogger(MainLoginDataTest::class.java)

        const val DEMO_LOGIN = "681200000124066965736431305516"

        const val DEMO_HEART = "681200000125066965736431305416"

        const val DEMO_ASK_STATE = "681200000123006216"
    }
}